package com.icinfo.cloud.provider.punish.common.nonlitigation.enums;

import com.icinfo.cloud.provider.common.enums.CertTypeEnum;
import lombok.Getter;
import org.springframework.util.ObjectUtils;

/**
 * 描述：非诉执行其他证件种类枚举类
 *
 * @author shishengyao
 * @description
 * @date 2022/4/9
 */
public enum NonLitigationCertTypeEnum {
    /**
     * 非诉执行其他证件种类枚举类
     */
    SFZ("15_000008-1", "居民身份证", CertTypeEnum.SFZ.getCode()),
    HZ("15_000008-2", "中国公民护照", CertTypeEnum.HZ.getCode()),
    TWTXZ("15_000008-3", "台湾居民来往大陆通行证", CertTypeEnum.CBR.getCode()),
    GATXZ("15_000008-4", "港澳居民来往内地通行证", CertTypeEnum.GAJM.getCode()),
    WGHZ("15_000008-5", "外国公民护照", CertTypeEnum.HZ.getCode()),
    HKB("15_000008-6", "户口薄", CertTypeEnum.HKB.getCode()),
    TYSHXYDM("15_000008-7", "统一社会信用代码证", ""),
    JDCJSZ("15_000008-8", "机动车驾驶证", ""),
    JGZJ("15_000008-9", "军警证件", ""),
    OTHER("15_000008-255", "其他", "");

    /**
     * 编码
     */
    @Getter
    private String code;
    /**
     * 描述
     */
    @Getter
    private String des;

    /**
     * 关联code
     */
    @Getter
    private String relCode;

    NonLitigationCertTypeEnum(String code, String des, String relCode) {
        this.code = code;
        this.des = des;
        this.relCode = relCode;
    }

    /**
     * 描述：根据relCode获取code
     *
     * @param relCode rel代码
     * @return {@link String }
     * @author shishengyao
     * @date 2022/04/09
     */
    public static String getCodeByRelCode(String relCode) {
        if (ObjectUtils.isEmpty(relCode)) {
            return null;
        }
        if (relCode.equals(CertTypeEnum.JRSFZ.getCode()) || relCode.equals(CertTypeEnum.WZJCSFZ.getCode())) {
            return NonLitigationCertTypeEnum.JGZJ.getCode();
        } else {
            for (NonLitigationCertTypeEnum e : NonLitigationCertTypeEnum.values()) {
                if (relCode.equals(e.getRelCode())) {
                    return e.getCode();
                }
            }
        }
        return relCode;
    }

    /**
     * 描述：根据code获取value
     *
     * @param code 编码
     * @return 描述内容
     * @author xiangyuyu
     * @date 2022-02-22 10:43
     */
    public static String getValueByCode(String code) {
        if (ObjectUtils.isEmpty(code)) {
            return null;
        }
        for (NonLitigationCertTypeEnum e : NonLitigationCertTypeEnum.values()) {
            if (code.equals(e.getCode())) {
                return e.getDes();
            }
        }
        return code;
    }

    /**
     * 描述：校验code是否是合法枚举
     *
     * @param code 枚举code
     * @return boolean 是否合法枚举（true-是/false-否）
     * @author xiangyuyu
     * @date 2022-02-22 10:42
     */
    public static boolean isLegalEnumCode(String code) {
        boolean flag = false;
        for (NonLitigationCertTypeEnum e : NonLitigationCertTypeEnum.values()) {
            if (e.getCode().equalsIgnoreCase(code)) {
                flag = true;
                break;
            }
        }
        return flag;
    }
}
